package com.loongtech.bi.action.bibusiness;

import com.loongtech.bi.action.BaseBiSearchAction;
import com.loongtech.bi.manager.business.ReconciliationBusinessChannelManager;
import com.loongtech.bi.manager.business.ReconciliationBusinessChannelManager.BusinessDataChannel;
import com.loongtech.bi.manager.system.GameParamConfigManager;
import com.loongtech.bi.support.CommonGameParam;
import com.loongtech.core.util.Time;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 账务工具—对帐查询Action
 * @author Marin
 * @date 2015年09月17日
 */
@Controller
@Scope("session")
@RequestMapping("/business/reconciliationBusinessChannel")
public class ReconciliationBusinessChannelBiAction extends BaseBiSearchAction {
	private static final long serialVersionUID = 1L;
	private List<BusinessDataChannel> dataList1;  // 获得汇总数据
	private List<BusinessDataChannel> dataList2;  // 获得详细数据
	
	@Autowired
	private ReconciliationBusinessChannelManager reconciliationBusinessChannelManager;

    @RequestMapping(value = "search.do", method = {RequestMethod.GET, RequestMethod.POST})
    public void search(HttpServletRequest request, HttpServletResponse response, @RequestParam String dstart, @RequestParam String dend, String callback) {
        Map<String, Object> result = new HashMap<>();
        try {
            dateStart = Time.formatDate(dstart, Time.TIMEPATTERN_SIMPLE);
            dateEnd = Time.formatDate(dend, Time.TIMEPATTERN_SIMPLE);

            //汇总数据
            dataList1 = reconciliationBusinessChannelManager.getBusinessSumData(dateStart, dateEnd);
            dataList2 = reconciliationBusinessChannelManager.getBusinessDetailData(dateStart, dateEnd);

            result.put("res", "0");
            result.put("dataList1", dataList1);
            result.put("dataList2", dataList2);

            printToJson(response, result, callback);
        } catch (Exception e) {
            e.printStackTrace();
            result.put("res", "1");
            result.put("msg", e.getMessage());
            printToJson(response, result, callback);
        }
	}
	
	//WEB直充
	public String getWebZhiChong() {
		return (String) GameParamConfigManager.getItemsRevise(CommonGameParam.WEBZHICHONG).keySet().toArray()[1];
	}

    @Override
    public void search() {

    }

    @Override
	protected String csvContent() {
		return "对账查询";
	}

	@Override
    protected String csvFileName() {
	    return "对账查询";
    }

	public List<BusinessDataChannel> getDataList1() {
		return dataList1;
	}

	public void setDataList1(List<BusinessDataChannel> dataList1) {
		this.dataList1 = dataList1;
	}

	public List<BusinessDataChannel> getDataList2() {
		return dataList2;
	}

	public void setDataList2(List<BusinessDataChannel> dataList2) {
		this.dataList2 = dataList2;
	}
}
